package com.mini.dubbo.provider.regist;

import redis.clients.jedis.Jedis;

import com.mini.dubbo.api.RedisConfig;
import com.mini.dubbo.api.RpcAnnotation;

/**
 * @author yzy
 * Created by yzy on 2021-12-04
 */
public class RedisRegisterCenterImpl implements IRegisterCenter {

    public void register(String serviceName, String address) {
        Jedis jedis = new Jedis(RedisConfig.redis_address, RedisConfig.redis_port);
        jedis.set(serviceName, address);
        System.out.println("redis regist success, serviceName = " + serviceName + " address = " + address);
    }

    public void publishService(Object... services) {
        for(Object service : services){
            RpcAnnotation annotation = service.getClass().getAnnotation(RpcAnnotation.class);
            String serviceName = annotation.value().getName();
            register(serviceName, RedisConfig.serviceAddress);
        }
    }
}
